package androidx.viewpager.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.graphics.drawable.Drawable;
import android.text.TextUtils.TruncateAt;
import android.text.method.SingleLineTransformationMethod;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.widget.TextViewCompat;
import androidx.viewpager.widget.ViewPager.DecorView;
import androidx.viewpager.widget.ViewPager.d;
import com.huawei.appgallery.festivalanimation.particle.modifiers.SizeModifier;
import com.huawei.hwphy2d.physical.util.BarrierParameters;
import java.lang.ref.WeakReference;
import java.util.Locale;
import o.PagerAdapter;

@DecorView
public class PagerTitleStrip extends ViewGroup {
    private static final int[] ˏॱ = new int[]{16843660};
    private static final int[] ͺ = new int[]{16842804, 16842901, 16842904, 16842927};
    private int ʻ;
    int ʼ;
    private int ʽ;
    ViewPager ˊ;
    private final a ˊॱ;
    TextView ˋ;
    private boolean ˋॱ;
    TextView ˎ;
    TextView ˏ;
    float ॱ;
    private WeakReference<PagerAdapter> ॱˊ;
    private int ॱˋ;
    private boolean ॱॱ;
    private int ᐝ;

    class a extends DataSetObserver implements ViewPager.OnPageChangeListener, d {
        final /* synthetic */ PagerTitleStrip ˊ;
        private int ˏ;

        a(PagerTitleStrip pagerTitleStrip) {
            this.ˊ = pagerTitleStrip;
        }

        public void onPageScrolled(int i, float f, int i2) {
            if (f > 0.5f) {
                i++;
            }
            this.ˊ.ˏ(i, f, false);
        }

        public void onPageScrollStateChanged(int i) {
            float f = 0.0f;
            if (this.ˏ == 0) {
                this.ˊ.ˎ(this.ˊ.ˊ.getCurrentItem(), this.ˊ.ˊ.getAdapter());
                if (this.ˊ.ॱ >= 0.0f) {
                    f = this.ˊ.ॱ;
                }
                this.ˊ.ˏ(this.ˊ.ˊ.getCurrentItem(), f, true);
            }
        }

        public void onPageScrolled(int i) {
            this.ˏ = i;
        }

        public void onAdapterChanged(ViewPager viewPager, PagerAdapter ozVar, PagerAdapter ozVar2) {
            this.ˊ.ˋ(ozVar, ozVar2);
        }

        public void onChanged() {
            float f = 0.0f;
            this.ˊ.ˎ(this.ˊ.ˊ.getCurrentItem(), this.ˊ.ˊ.getAdapter());
            if (this.ˊ.ॱ >= 0.0f) {
                f = this.ˊ.ॱ;
            }
            this.ˊ.ˏ(this.ˊ.ˊ.getCurrentItem(), f, true);
        }
    }

    static class b extends SingleLineTransformationMethod {
        private Locale ˏ;

        b(Context context) {
            this.ˏ = context.getResources().getConfiguration().locale;
        }

        public CharSequence getTransformation(CharSequence charSequence, View view) {
            CharSequence transformation = super.getTransformation(charSequence, view);
            return transformation != null ? transformation.toString().toUpperCase(this.ˏ) : null;
        }
    }

    private static void ˊ(TextView textView) {
        textView.setTransformationMethod(new b(textView.getContext()));
    }

    public PagerTitleStrip(@NonNull Context context) {
        this(context, null);
    }

    public PagerTitleStrip(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        boolean z = false;
        super(context, attributeSet);
        this.ʽ = -1;
        this.ॱ = SizeModifier.STABLE_STATE_SCALE;
        this.ˊॱ = new a(this);
        View textView = new TextView(context);
        this.ˋ = textView;
        addView(textView);
        textView = new TextView(context);
        this.ˎ = textView;
        addView(textView);
        textView = new TextView(context);
        this.ˏ = textView;
        addView(textView);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, ͺ);
        int resourceId = obtainStyledAttributes.getResourceId(0, 0);
        if (resourceId != 0) {
            TextViewCompat.ˎ(this.ˋ, resourceId);
            TextViewCompat.ˎ(this.ˎ, resourceId);
            TextViewCompat.ˎ(this.ˏ, resourceId);
        }
        int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(1, 0);
        if (dimensionPixelSize != 0) {
            setTextSize(0, (float) dimensionPixelSize);
        }
        if (obtainStyledAttributes.hasValue(2)) {
            dimensionPixelSize = obtainStyledAttributes.getColor(2, 0);
            this.ˋ.setTextColor(dimensionPixelSize);
            this.ˎ.setTextColor(dimensionPixelSize);
            this.ˏ.setTextColor(dimensionPixelSize);
        }
        this.ᐝ = obtainStyledAttributes.getInteger(3, 80);
        obtainStyledAttributes.recycle();
        this.ʼ = this.ˎ.getTextColors().getDefaultColor();
        setNonPrimaryAlpha(0.6f);
        this.ˋ.setEllipsize(TruncateAt.END);
        this.ˎ.setEllipsize(TruncateAt.END);
        this.ˏ.setEllipsize(TruncateAt.END);
        if (resourceId != 0) {
            obtainStyledAttributes = context.obtainStyledAttributes(resourceId, ˏॱ);
            z = obtainStyledAttributes.getBoolean(0, false);
            obtainStyledAttributes.recycle();
        }
        if (z) {
            ˊ(this.ˋ);
            ˊ(this.ˎ);
            ˊ(this.ˏ);
        } else {
            this.ˋ.setSingleLine();
            this.ˎ.setSingleLine();
            this.ˏ.setSingleLine();
        }
        this.ʻ = (int) (context.getResources().getDisplayMetrics().density * 16.0f);
    }

    public void setTextSpacing(int i) {
        this.ʻ = i;
        requestLayout();
    }

    public int ˊ() {
        return this.ʻ;
    }

    public void setNonPrimaryAlpha(@FloatRange(from = 0.0d, to = 1.0d) float f) {
        this.ॱˋ = ((int) (255.0f * f)) & 255;
        int i = (this.ॱˋ << 24) | (this.ʼ & 16777215);
        this.ˋ.setTextColor(i);
        this.ˏ.setTextColor(i);
    }

    public void setTextColor(@ColorInt int i) {
        this.ʼ = i;
        this.ˎ.setTextColor(i);
        int i2 = (this.ॱˋ << 24) | (this.ʼ & 16777215);
        this.ˋ.setTextColor(i2);
        this.ˏ.setTextColor(i2);
    }

    public void setTextSize(int i, float f) {
        this.ˋ.setTextSize(i, f);
        this.ˎ.setTextSize(i, f);
        this.ˏ.setTextSize(i, f);
    }

    public void setGravity(int i) {
        this.ᐝ = i;
        requestLayout();
    }

    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        ViewParent parent = getParent();
        if (parent instanceof ViewPager) {
            ViewPager viewPager = (ViewPager) parent;
            PagerAdapter ˎ = viewPager.getAdapter();
            viewPager.ˏ(this.ˊॱ);
            viewPager.removeOnPageChangeListener(this.ˊॱ);
            this.ˊ = viewPager;
            ˋ(this.ॱˊ != null ? (PagerAdapter) this.ॱˊ.get() : null, ˎ);
            return;
        }
        throw new IllegalStateException("PagerTitleStrip must be a direct child of a ViewPager.");
    }

    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (this.ˊ != null) {
            ˋ(this.ˊ.getAdapter(), null);
            this.ˊ.ˏ(null);
            this.ˊ.removeOnAdapterChangeListener(this.ˊॱ);
            this.ˊ = null;
        }
    }

    void ˎ(int i, PagerAdapter ozVar) {
        CharSequence charSequence;
        CharSequence charSequence2 = null;
        int ˎ = ozVar != null ? ozVar.getCount() : 0;
        this.ॱॱ = true;
        if (i < 1 || ozVar == null) {
            charSequence = null;
        } else {
            charSequence = ozVar.getPageTitle(i - 1);
        }
        this.ˋ.setText(charSequence);
        TextView textView = this.ˎ;
        if (ozVar == null || i >= ˎ) {
            charSequence = null;
        } else {
            charSequence = ozVar.getPageTitle(i);
        }
        textView.setText(charSequence);
        if (i + 1 < ˎ && ozVar != null) {
            charSequence2 = ozVar.getPageTitle(i + 1);
        }
        this.ˏ.setText(charSequence2);
        ˎ = MeasureSpec.makeMeasureSpec(Math.max(0, (int) (((float) ((getWidth() - getPaddingLeft()) - getPaddingRight())) * 0.8f)), Integer.MIN_VALUE);
        int makeMeasureSpec = MeasureSpec.makeMeasureSpec(Math.max(0, (getHeight() - getPaddingTop()) - getPaddingBottom()), Integer.MIN_VALUE);
        this.ˋ.measure(ˎ, makeMeasureSpec);
        this.ˎ.measure(ˎ, makeMeasureSpec);
        this.ˏ.measure(ˎ, makeMeasureSpec);
        this.ʽ = i;
        if (!this.ˋॱ) {
            ˏ(i, this.ॱ, false);
        }
        this.ॱॱ = false;
    }

    public void requestLayout() {
        if (!this.ॱॱ) {
            super.requestLayout();
        }
    }

    void ˋ(PagerAdapter ozVar, PagerAdapter ozVar2) {
        if (ozVar != null) {
            ozVar.unregisterDataSetObserver(this.ˊॱ);
            this.ॱˊ = null;
        }
        if (ozVar2 != null) {
            ozVar2.registerDataSetObserver(this.ˊॱ);
            this.ॱˊ = new WeakReference(ozVar2);
        }
        if (this.ˊ != null) {
            this.ʽ = -1;
            this.ॱ = SizeModifier.STABLE_STATE_SCALE;
            ˎ(this.ˊ.getCurrentItem(), ozVar2);
            requestLayout();
        }
    }

    void ˏ(int i, float f, boolean z) {
        if (i != this.ʽ) {
            ˎ(i, this.ˊ.getAdapter());
        } else if (!z && f == this.ॱ) {
            return;
        }
        this.ˋॱ = true;
        int measuredWidth = this.ˋ.getMeasuredWidth();
        int measuredWidth2 = this.ˎ.getMeasuredWidth();
        int measuredWidth3 = this.ˏ.getMeasuredWidth();
        int i2 = measuredWidth2 / 2;
        int width = getWidth();
        int height = getHeight();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        int paddingTop = getPaddingTop();
        int paddingBottom = getPaddingBottom();
        int i3 = paddingRight + i2;
        int i4 = (width - (paddingLeft + i2)) - i3;
        float f2 = 0.5f + f;
        if (f2 > 1.0f) {
            f2 -= 1.0f;
        }
        i4 = ((width - i3) - ((int) (f2 * ((float) i4)))) - (measuredWidth2 / 2);
        i3 = i4 + measuredWidth2;
        i2 = this.ˋ.getBaseline();
        measuredWidth2 = this.ˎ.getBaseline();
        int baseline = this.ˏ.getBaseline();
        int max = Math.max(Math.max(i2, measuredWidth2), baseline);
        i2 = max - i2;
        measuredWidth2 = max - measuredWidth2;
        baseline = max - baseline;
        int measuredHeight = this.ˏ.getMeasuredHeight() + baseline;
        max = Math.max(Math.max(this.ˋ.getMeasuredHeight() + i2, this.ˎ.getMeasuredHeight() + measuredWidth2), measuredHeight);
        switch (this.ᐝ & 112) {
            case 16:
                paddingTop = (((height - paddingTop) - paddingBottom) - max) / 2;
                height = paddingTop + i2;
                measuredWidth2 += paddingTop;
                i2 = paddingTop + baseline;
                break;
            case 80:
                paddingTop = (height - paddingBottom) - max;
                height = paddingTop + i2;
                measuredWidth2 += paddingTop;
                i2 = paddingTop + baseline;
                break;
            default:
                height = paddingTop + i2;
                measuredWidth2 += paddingTop;
                i2 = paddingTop + baseline;
                break;
        }
        this.ˎ.layout(i4, measuredWidth2, i3, this.ˎ.getMeasuredHeight() + measuredWidth2);
        measuredWidth2 = Math.min(paddingLeft, (i4 - this.ʻ) - measuredWidth);
        this.ˋ.layout(measuredWidth2, height, measuredWidth + measuredWidth2, this.ˋ.getMeasuredHeight() + height);
        measuredWidth2 = Math.max((width - paddingRight) - measuredWidth3, this.ʻ + i3);
        this.ˏ.layout(measuredWidth2, i2, measuredWidth2 + measuredWidth3, this.ˏ.getMeasuredHeight() + i2);
        this.ॱ = f;
        this.ˋॱ = false;
    }

    protected void onMeasure(int i, int i2) {
        if (MeasureSpec.getMode(i) != 1073741824) {
            throw new IllegalStateException("Must measure with an exact width");
        }
        int paddingTop = getPaddingTop() + getPaddingBottom();
        int childMeasureSpec = getChildMeasureSpec(i2, paddingTop, -2);
        int size = MeasureSpec.getSize(i);
        int childMeasureSpec2 = getChildMeasureSpec(i, (int) (((float) size) * BarrierParameters.FRICTION), -2);
        this.ˋ.measure(childMeasureSpec2, childMeasureSpec);
        this.ˎ.measure(childMeasureSpec2, childMeasureSpec);
        this.ˏ.measure(childMeasureSpec2, childMeasureSpec);
        if (MeasureSpec.getMode(i2) == 1073741824) {
            paddingTop = MeasureSpec.getSize(i2);
        } else {
            paddingTop = Math.max(ˋ(), paddingTop + this.ˎ.getMeasuredHeight());
        }
        setMeasuredDimension(size, View.resolveSizeAndState(paddingTop, i2, this.ˎ.getMeasuredState() << 16));
    }

    protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        float f = 0.0f;
        if (this.ˊ != null) {
            if (this.ॱ >= 0.0f) {
                f = this.ॱ;
            }
            ˏ(this.ʽ, f, true);
        }
    }

    int ˋ() {
        Drawable background = getBackground();
        if (background != null) {
            return background.getIntrinsicHeight();
        }
        return 0;
    }
}
